package com.yunfei.procedure;

import oracle.jdbc.OracleTypes;

import java.sql.*;

/**
* @Description: 撤销撤销成功后，需要异步调用的存储过程
 * pkg_yl_his_data.sp_autoReserveArrange_yl
 * @param:(sreasoncode out varchar2,sreasoninfo out varchar2,p_proserialno in varchar2,p_reserveno in varchar2)
* @Author: zhengyunfei
* @Date: 2019/2/15
* @time:16:44
*/
public class ProductCheXiaoProcedure {
    private Connection conn;
    private CallableStatement stat;
    private ResultSet rs;
    String pkChkLoginSql = "call pkg_yl_his_data.sp_autoReserveArrange_yl(?,?,?,?)";
    /**
    * @Description: 存储过程，撤销成功之后异步去调用
     * @param p_proserialno 产品id
     * @param p_reserveno 预约编号
    * @return: 孙总说了，不用处理返回结果
    * @Author: zhengyunfei
    * @Date: 2018/4/24
    * @time:13:49
    */
    public ProcedureResultModel callProcedure(String url,String driverName,String username,String password,String resverno,String projId) {
        ProcedureResultModel result=new ProcedureResultModel();
        try {
            Class.forName(driverName);
            conn = DriverManager.getConnection(url, username, password);
            stat = conn.prepareCall(pkChkLoginSql);
            // 2个输入参数和2个输出参数
            stat.setString(3, projId);
            stat.setString(4, resverno);
            stat.registerOutParameter(1, OracleTypes.VARCHAR);
            stat.registerOutParameter(2, OracleTypes.VARCHAR);
            stat.execute();
            //返回结果
            String returnCode= stat.getString(1);//处理结果 0:失败 1成功
            String returnInfo= stat.getString(2);//处理结果描述
            result.setReturnCode(returnCode);
            result.setReturnInfo(returnInfo);
            System.out.println("sal: " + result.getReturnCode()+","+result.getReturnInfo());
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            close(conn, stat, rs);
        }
        return result;
    }

    // 关闭连接
    public void close(Connection conn, CallableStatement stat, ResultSet rs) {
        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            } finally {
                rs = null;
            }
        }
        if (stat != null) {
            try {
                stat.close();
            } catch (SQLException e) {
                e.printStackTrace();
            } finally {
                stat = null;
            }
        }
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            } finally {
                conn = null;
            }
        }
    }

    public static void main(String[] args) {
       // new GetTouZiZheRenZhengInfoProcedure().callProcedure("20180417132146779447466");
    }
}